<template>
  <view class="content">
    <HeadNav title="登录授权" />
    <view class="logo-box">
      <image
        class="logo"
        src="https://ucp-tcg.com:18001/mc/app/static/login.png"
      ></image>
      <view class="text-area">
        <text class="title">{{ title }}</text>
      </view>
    </view>

    <view class="login-box">
      <!-- <view class="cb-box">
				<checkbox-group>
					<label>
						<checkbox value="cb" />
						<text class="cb-text">我已阅读，理解并接收《隐私政策》和《用户协议》</text>
					</label>
				</checkbox-group>
			</view> -->

      <button
        type="primary"
        open-type="getPhoneNumber"
        @getphonenumber="getPhoneNumber"
        style="background-color: #07c062"
      >
        手机号快速登录
      </button>
      <!-- <button type="primary" @click="getPhoneNumber">手机号快速登录</button> -->
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
// import {
// 	loginApi
// } from '@/api/user'
import HeadNav from '@/components/HeadNav'
import { useUserStore } from '@/stores'
import { onLoad, onShareAppMessage } from '@dcloudio/uni-app'
const title = ref('TCG小程序登录以使用更多功能')
const cb = ref(false)
const redirectUrl = ref('')

onLoad(options => {
  console.log('options', options)
  redirectUrl.value = options.redirectUrl
})

const getPhoneNumber = async e => {
  // console.log(e)
  console.log(e.detail.code) // 动态令牌
  // console.log(e.detail.errMsg) // 回调信息（成功失败都会返回）
  // console.log(e.detail) // 错误码（失败时返回）
  if (!e.detail.code) {
    return uni.showToast({
      icon: 'none',
      title: '已取消登录'
    })
  }
  uni.showLoading({
    title: '正在登录...'
  })
  const userStore = useUserStore()
  await userStore.login(e.detail.code)
  // await userStore.login('test')
  uni.hideLoading()
  uni.switchTab({
    url: redirectUrl.value ? redirectUrl.value : '/pages/index/index'
  })
}
</script>

<style>
.content {
  /* display: flex; */
  /* flex-direction: column; */
  /* align-items: center; */
  /* justify-content: center; */
  /* height: 100vh; */
}

.logo-box {
  padding-top: 300rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 220rpx;
  text-align: center;
  background: url('https://ucp-tcg.com:18001/mc/app/static/login-bg.png')
    no-repeat;
  background-size: cover;
}

.logo {
  height: 328rpx;
  width: 328rpx;
}

.text-area {
  display: flex;
  justify-content: center;
  padding-top: 40rpx;
}

.title {
  font-size: 36rpx;
  /* color: #8f8f94; */
}

.cb-box {
  padding-bottom: 32rpx;
}

.cb-text {
  font-size: 28rpx;
  color: #8f8f94;
}

.login-box {
  width: 100%;
  padding: 0 32rpx;
  box-sizing: border-box;
  /* position: absolute; */
  /* bottom: 200rpx; */
}
</style>
